 #include "../views.hpp"
 
using lms::views::CustomerView;

CustomerView::CustomerView()
{
 option = 0;
 fullName = "";
 address = "";
 contactNumber = "";
 email = "";
 customer = null;
 UnitOfWork& unitOfWork = UnitOfWork::getInstance();
 customerServices = unitOfWork.GetCustomerServices();
 
}

Customer* CustomerView::createCustomer()
{
   
 Utilities::printText("\n\t\tIntroducing of Customers\n");
 fullName = Utilities::reinterpret_input<string>("\tEnter the Full Name: ");
 contactNumber = Utilities::reinterpret_input<string>("\tEnter the Contact Number: ");
 address = Utilities::reinterpret_input<string>("\tEnter the Contact Address: ");
 email = Utilities::reinterpret_input<string>("\tEnter the Email: ");
 customer = new Customer(fullName,contactNumber,address,email);
 return customer;
 
}

void CustomerView::add()
{
     customer = createCustomer();
     customerServices->add( customer );     
}

void CustomerView::remove()
{
     showCustomers();
     option = Utilities::reinterpret_input<int>("Choose Which Delete: ");
     option--;
     customerServices->remove( option );

}
void CustomerView::edit()
{
     showCustomers();
     option = Utilities::reinterpret_input<int>("Choose Which Modify: ");
     option--;
     customer = createCustomer(); 
     customerServices->edit( customer,option );
}

void CustomerView::showCustomers()
{

Node<Customer>* i = (customerServices->get())->getFirst();
int x = 1;
     Utilities::printText("\t Lists Of Customers\n");
while(i != NULL){
   
        cout << "\tCustomer No." << x++ << "\n";
        cout << "\tFullName: " << i->getData()->getFullName() <<"\n"; 
        cout << "\tContact Number: " << i->getData()->getContactNumber() << "\n";
        cout << "\tAddress: " << i->getData()->getAddress() << "\n";
        cout << "\tEmail: " << i->getData()->getEmail() << "\n\n";
        i = i->getNext();        
  }      
} 
 
void CustomerView::show(){
    do{
 Utilities::clearScreen(); 
 Utilities::printText( "\n\t\tMaintenances Of Customers\n"); 
 Utilities::printText("\t1. Add Customer: \n");
 Utilities::printText("\t2. List All: \n");
 Utilities::printText("\t3. Delete Customer: \n");
 Utilities::printText("\t4. Modify Customer: \n");
 Utilities::printText("\t5. Exit: \n");
 option = Utilities::reinterpret_input<int>("\t\tChoose The Option: ");
 
 switch(option){
 
 case 1:
  Utilities::clearScreen();   
  add(); 
  break;

 case 2:
  Utilities::clearScreen();
  showCustomers();
  Utilities::pause();
  break;
         
 case 3: 
  Utilities::clearScreen(); 
  edit(); 
  break;
  
 case 4: 
  Utilities::clearScreen();
  remove(); 
  break;
  
     case 5:
         break;
 default:
  Utilities::printText("\tInvalid Option\n");
  Utilities::pause();
   break;
    }  
  }while(option != 5);
}
